<?php
class Config
{

    public $__version = "1.0";
    public $__classname = "Config";
    public $__sql = array( '1.0' => "create table k_config (id varchar(50) not null, ap varchar(50) not null, value varchar(150) not null, primary key(id,ap) );" );
    public $cache = array( "" );

    public function Get( $id, $ap = "" )
    {
        if ( isset( $this->cache[$ap][$id] ) )
        {
            return $this->cache[$ap][$id];
        }
        $ret = "";
        $rs = getdb( "!!select value from k_config where id='{$id}' and ap='{$ap}' LIMIT 0,1" );
        if ( !$rs->eof )
        {
            $ret = $rs->f[0];
        }
        $this->cache[$ap][$id] = $ret;
        return $ret;
    }

    public function Set( $id, $value, $ap = "" )
    {
        $uid = isset( $_SESSION['uid'] ) ? intval( $_SESSION['uid'] ) : 0;
        $dt = date( "Y-m-d H:i:s", systime( ) );
        getdb( "INSERT INTO `k_config` (`id`,`ap`,`value`,updateid,updatedt) VALUES ('{$id}','{$ap}','{$value}',{$uid},'{$dt}') ON DUPLICATE KEY UPDATE `value`='{$value}',`updateid`={$uid} , `updatedt`='{$dt}'" );
        $this->cache[$ap][$id] = $value;
    }

}

?>